<?php

/**
 * Docente actions.
 *
 * @package    fiei
 * @subpackage Docente
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class DocenteActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeList(sfWebRequest $request)
  {
    $json         = new Services_JSON();
    $page         = $request->getParameter('page'); // get the requested page 
    $limit        = $request->getParameter('rows'); // get how many rows we want to have into the grid 
    $sidx         = $request->getParameter('sidx'); // get index row - i.e. user click to sort 
    $sord         = $request->getParameter('sord'); // get the direction 
    $searchField  =	$request->getParameter('searchFiel');
    $searchOper	  = $request->getParameter('searchOper');
    $searchString =	$request->getParameter('searchString');
    $q = Doctrine_Query::create()
         ->select('*')
         ->from('Docente d');
    if($sidx)
    {
      $q->orderBy(sprintf("d.%s %s", $sidx, $sord));
    }
    
    $this->pager = new sfDoctrinePager('Docente', 20);
    $this->pager->setQuery($q);
    $this->pager->setPage($page);
    $this->pager->init();
   
   $this->docentes = $this->pager->getResults();
  
   $responce['page']    = $page; 
   $responce['total']   = $this->pager->getLastPage(); 
   $responce['records'] = $q->execute()->count(); 
    
   foreach($this->docentes as $key => $docente) 
   { 
     $responce['rows'][$key]['id']   = $docente->getId(); 
     $responce['rows'][$key]['cell'] = array(
                                          $docente->getDni(),
                                          $docente->getNombres()." ".$docente->getApellidoPaterno(),
                                          $docente->getCorreo(),
                                          $docente->getFechaNacimiento(),
                                          $docente->getTelefono()
                                          ); 
   } 
   return $this->renderText($json->encode($responce));
  }
}